<template>
    <div class="stock-close-shadow" @click="closeStockCloseModel" v-show="show_close_stock">
        <div class="stock-close" @click.stop="">
            <div class="stock-info">
                <div class="title">{{ stock_close_order.symbol }}</div>
                <div class="more">
                    <div class="value">price: ${{ stock_close_order.price }}</div>
                    <!-- <div class="mover" :style="`color: ${ parseFloat(stock_close_order.change) >= 0 ? 'var(--positive-number-color)' : 'var(--negative-number-color)' }`">{{ active_stock?.change }}</div> -->
                </div>
            </div>
            <div class="tabbar">
                <div class="tabbar-item" v-for="item in tabbar" :key="item.id" :style="`background-color: ${ item.id == active_tabbar.id ? '#ccc' : '#00000000' }`" @click="active_tabbar = item">{{ item.text }}</div>
            </div>
            <div class="form-box">
                <div class="input-name">Type</div>
                <div class="input-line">
                    <select name="orderType" id="orderType" v-model="active_trading_type">
                        <option :value="item.value" v-for="item in trading_type_list" :key="item.id">{{ item.text }}</option>
                    </select>
                </div>
                <div class="input-name">Quantity</div>
                <div class="input-line">
                    <input type="number" min="1" v-model="stockCloseQuantity">
                </div>
                <div class="input-name" v-show="active_trading_type == 1">Limit Price</div>
                <div class="input-line" v-show="active_trading_type == 1">
                    <input type="number" min="1" v-model="limit_price" step="0.01">
                </div>
                <div class="price-per-share-box">
                    <div class="price-box">
                        <div class="price-name">Price per share</div>
                        <div class="price">{{ stockCloseMarketPrice }}</div>
                    </div>
                    <div class="count-box">
                        <div class="quantity">Quantity</div>
                        <div class="count">{{ stockCloseQuantity }}</div>
                    </div>
                    <div class="total-cost">
                        <div class="total-text">Total Cost</div>
                        <div class="total-price">{{ stockCloseTotalPrice }}</div>
                    </div>
                    <div class="current-holdings">
                        <div class="total-text">Current Holdings</div>
                        <div class="total-price">{{ stock_close_order.shares }}</div>
                    </div>
                    <div class="account-balance">
                        <div class="total-text">Account Balance</div>
                        <div class="total-price" style="color: var(--positive-number-color); font-weight: 500;">${{ userInfo.balance }}</div>
                    </div>
                    <div class="btn-box" :style="`background-color: ${ active_tabbar.id == 1 ? 'var(--positive-number-color)' : 'var(--negative-number-color)' }`" @click="tradingService.stockClose">
                        <div class="btn">{{ active_tabbar.text }} {{ stock_close_order.symbol }}</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { userInfo } from '@/service/user';
import { show_close_stock, closeStockCloseModel, stock_close_order } from '@/service/asset';
import { tabbar, active_tabbar, trading_type_list, active_trading_type, limit_price, stockCloseQuantity, stockCloseMarketPrice, stockCloseTotalPrice, tradingService } from '@/service/trade.js';
</script>

<style scoped lang="less">
.stock-close-shadow {
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    background-color: #88888880;

    .stock-close {
        box-sizing: border-box;
        width: 30vw;
        background-color: #fff;
        border-radius: 0.5vw;
        display: flex;
        flex-direction: column;
        gap: 1vw;
        padding: 1vw;

        .stock-info {
            display: flex;
            justify-content: space-between;
            align-items: center;

            .title {
                font-size: 1.5vw;
                font-weight: 600;
                color: var(--text-color);
            }

            .more {
                display: flex;
                flex-direction: column;
                align-items: flex-end;

                .value {
                    font-size: 1vw;
                    font-weight: 600;
                    color: var(--text-color);
                }

                .mover {
                    font-size: 0.7vw;
                    color: var(--positive-number-color);
                }
            }
        }

        .tabbar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            background-color: #f5f5f5;
            padding: 0.3vw;
            border-radius: 0.5vw;

            .tabbar-item {
                flex: 1;
                text-align: center;
                border-radius: 0.5vw;
                padding: 0.2vw;
            }
        }

        .form-box {
            display: flex;
            flex-direction: column;
            gap: 1vw;

            .input-name {
                font-size: 0.9vw;
                color: var(--text-color);
            }

            .input-line {
                padding: 0.3vw;
                border-radius: 0.3vw;
                background-color: var(--bg-strong-color);

                input {
                    box-sizing: border-box;
                    width: 100%;
                    padding-left: 0.5vw;
                    background-color: #00000000;
                    border: 0;
                    outline: 0;
                }

                select {
                    width: 100%;
                    height: 100%;
                    background-color: #ffffff00;
                    border: 0;
                    outline: 0;
                    display: flex;

                    .select-item {
                        flex: 1;
                        text-align: center;
                        border-radius: 0.5vw;
                        padding: 0.2vw;
                    }
                }
            }

            .price-per-share-box {
                display: flex;
                flex-direction: column;
                gap: 0.5vw;

                .price-box {
                    display: flex;
                    justify-content: space-between;

                    &>div {
                        font-size: 0.8vw;
                    }
                }

                .count-box {
                    display: flex;
                    justify-content: space-between;

                    &>div {
                        font-size: 0.8vw;
                    }
                }

                .total-cost, .current-holdings, .account-balance {
                    display: flex;
                    justify-content: space-between;
                    border-top: 0.1vw solid var(--border-color);
                    margin-top: 0.5vw;
                    padding-top: 0.5vw;

                    &>div {
                        font-size: 0.9vw;
                    }
                }

                .current-holdings, .account-balance {
                    border: 0;
                    margin-top: 0;
                    padding-top: 0;
                }

                .btn-box {
                    margin-top: 2vw;
                    width: 100%;
                    height: 2.5vw;
                    border-radius: 0.5vw;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    position: relative;

                    &::after {
                        content: '';
                        display: block;
                        width: 100%;
                        height: 100%;
                        border-radius: 0.5vw;
                        position: absolute;
                        top: 0;
                        left: 0;
                    }

                    &:hover::after {
                        background-color: #00000020;
                    }

                    .btn {
                        font-size: 0.8vw;
                        color: #fff;
                    }
                }
            }
        }
    }
}
</style>